//
//  IDCViewController.m
//  GamePlan
//
//  Created by iD Student on 7/15/13.
//  Copyright (c) 2013 jasonkurtzman. All rights reserved.
//

#import "IDCViewController.h"
#import "IDCTutorialViewController.h"

@interface IDCViewController ()

@end

@implementation IDCViewController
@synthesize imageView, iconsView, scrollView, lessons, lessonButton, lessonLabel, lessonText;

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    lessons = [[NSMutableArray alloc]init];
    
    //Create lessons here
    [lessons addObject:@"Intro to\nXCode"];
    [lessons addObject:@"Types"];
    [lessons addObject:@"Variables\n& Objects"];
    [lessons addObject:@"Buttons"];
    [lessons addObject:@"IBOutlets"];
    [lessons addObject:@"Labels"];
    [lessons addObject:@"Images"];
    [lessons addObject:@"Changing\nImages"];
    [lessons addObject:@"Strings"];
    [lessons addObject:@"Sounds"];
    [lessons addObject:@"Icons"];
    [lessons addObject:@"Spash\nScreens"];
    [lessons addObject:@"Methods &\nFunctions"];
    [lessons addObject:@"Parameters"];
    [lessons addObject:@"Alert Views"];
    [lessons addObject:@"Random\nNumbers"];
    [lessons addObject:@"Animations"];
    [lessons addObject:@"NSLog"];
    [lessons addObject:@"Rock, Paper, \nScissors"];
    [lessons addObject:@"New View\nController"];
    [lessons addObject:@"Switching view \ncontrollers"];
    //Stoped Creating lessons
    
    imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"black.png"]];
    //imageView = [[UIImageView alloc] init];
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Map" style:UIBarButtonItemStyleBordered target:self action:@selector(backPressed)];
    self.navigationItem.leftBarButtonItem = backButton;
    self.navigationController.view.backgroundColor = [UIColor blackColor];
    self.navigationItem.title = [NSString stringWithFormat:@"Game Plan || Level: %d", 0];
    
    
    scrollView.contentSize = CGSizeMake(imageView.frame.size.width, imageView.frame.size.height);
    scrollView.maximumZoomScale = 4.0;
    scrollView.minimumZoomScale = 0.75;
    scrollView.clipsToBounds = YES;
    scrollView.delegate = self;
    [scrollView addSubview:imageView];
    
   /* for(int x = 0; x < 10; x++)
    {
//        iconsView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon.png"]];
        iconsView = [[UIImageView alloc] initWithFrame:CGRectMake(10, x * 60, 50, 50)];
        [iconsView setTag:x];
        [iconsView setImage:[UIImage imageNamed:@"icon.png"]];
        [iconsView setUserInteractionEnabled:YES];
        [scrollView addSubview:iconsView];
        [lessons addObject:iconsView];
    }*/
    
    int currentX = 70;
    int currentY = 70;
    
    for(int i = 0; i < lessons.count; i++)
    {
        
        lessonButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [lessonButton setBackgroundImage:[UIImage imageNamed:@"icon.png"] forState:UIControlStateNormal];
        lessonButton.frame = CGRectMake(currentX, currentY, 40, 40);
        [lessonButton setTag:i];
        [lessonButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [scrollView addSubview:lessonButton];
        
        //Labels
//        lessonLabel = [[UILabel alloc] init];
//        lessonLabel.text = [lessons objectAtIndex:i];
//        lessonLabel.textColor = [UIColor whiteColor];
//        lessonLabel.backgroundColor = [UIColor blackColor];
//        lessonLabel.frame = CGRectMake(currentX, currentY+ 40, 200, 18);
//        [scrollView addSubview:lessonLabel];
        
        NSString *obj = [lessons objectAtIndex:i];
        
        
        //UITextView attempt
        lessonText = [[UITextView alloc] init];
        lessonText.text = [obj stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
        lessonText.textColor = [UIColor whiteColor];
        lessonText.backgroundColor = [UIColor blackColor];
        lessonText.userInteractionEnabled = NO;
        lessonText.frame = CGRectMake(currentX - 5, currentY + 40, 200, 45);
        [scrollView addSubview:lessonText];
        
        currentX +=120;
        
        if(i % 4 == 3) {
            currentY +=100;
            currentX = 70;
        }
        
        
        
        
    }
	// Do any additional setup after loading the view, typically from a nib.
}

-(IBAction)buttonClicked:(id)sender
{
    NSLog(@"Button: %d clicked.", [sender tag]);
    
    
    IDCTutorialViewController *vc = [[IDCTutorialViewController alloc] init];
    vc.model = [NSString stringWithFormat:@"Modal %d", [sender tag]];
    
    
    //[self presentViewController:vc animated:YES completion:NULL];
    [self.navigationController pushViewController:vc animated:YES];
    
    
}

-(void) backPressed
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
